package com.penghaonan.appframework.utils

import android.content.Context
import android.os.Looper
import com.penghaonan.appframework.AppDelegate
import com.penghaonan.appframework.utils.threadpool.AThreadPool
import com.penghaonan.appframework.utils.threadpool.IThreadPoolHolder

class ThreadUtils {
    companion object {
        @JvmStatic
        fun getThreadPool(context: Context): AThreadPool {
            var threadPool: AThreadPool? = null
            if (context is IThreadPoolHolder) {
                threadPool = (context as IThreadPoolHolder).ioThreadPool
            }
            if (threadPool == null) {
                threadPool = AppDelegate.getIOThreadPool()
            }
            return threadPool
        }

        fun isMainThread(): Boolean {
            return Looper.myLooper() == Looper.getMainLooper()
        }
    }
}